package com.iceland.common.message;

public class CmdMessage implements Message{
    int type;
    //请求头
    Header header;
    //需要转发的数据
    Object data;

    DataType dataType;

    public CmdMessage(int type, Header header, Object data) {
        this.type = type;
        this.header = header;
        this.data = data;
    }
    public CmdMessage(int type) {
        this.type = type;
        this.header = new Header();
    }


    public int getType(){
        return type;
    }

    public Header getHeader(){
        return header;
    }
    public String getHeader(HeaderType key){
        if(header==null){
            return null;
        }
        return header.get(key.type);
    }

    public void putHeader(HeaderType key,String value){
        if(header==null){
            header=new Header();
        }
        header.set(key,value);
    }

    public <T> T getData(){
        if(data==null){
            return null;
        }
        return (T)data;
    }

    public void setType(int type) {
        this.type = type;
    }

    public void setData(Object data) {
            this.data = data;
    }

    public DataType getDataType() {
        return dataType;
    }

    public void setDataType(DataType dataType) {
        this.dataType = dataType;
    }
}
